<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 对象的解构赋值
        var obj = {
            name:'tom',
            age:10
        }
       /*  var name = obj.name;
        var age = obj.age;
        console.log(name,age); */

        const obj1 = {
            name:'xiaowangzi',
            age:19
        }
       /*  let name = obj1.name;
        let age = obj1.age;
        console.log(name,age); */
     /*    let {name,age} = obj1;
        console.log(name,age); */
       /*  let {name,age} = {
            name:'tom',
            age:15
        }
        console.log(name,age); */

       /*  let name1 = obj1.name;
        let age = obj1.age;
        console.log(name1,age); */
        // 不建议这种方式
     /*    let {name:name1,age} = obj1;
        console.log(name,age);
 */
        // 默认值
        const obj2 = {
            name:'yaoshang',
            age:18,
            // msg:'年纪小，体力好'
        }
        let {name,age,msg="xx"} = obj2;//msg='xx'默认值，在对象中没有相关的属性名，使用默认值，若有，使用该对象中的这个值
        console.log(name,age,msg);


        // 数组的解构赋值
        const arr = [1,'2',null,obj2,'xx'];
        let a1= arr[0];
        let a2 = arr[1];
        console.log(a1,a2);
        let [b1,b2,b3,b4] = arr;
        console.log(b1,b2,b3,b4);
        let [,c1,,c3]= arr;//可以使用逗号进行占位
        console.log(c1,c3);

        let [d1,,,d4,d5='胡浩荣'] =arr;//默认值
        console.log(d1,d4,d5);
    </script>
</body>
</html>